﻿Imports System.Drawing
Imports System.Drawing.Imaging

Public Class ColorConverter
    Public Function ConvertTo(ByVal Source As bitmap, ByVal NewFormat As pixelformat) As bitmap
        If Source.PixelFormat <> NewFormat Then
            Dim temp As Bitmap = AForge.Imaging.Image.Clone(Source, NewFormat)
            Return temp
        Else
            Return Source
        End If
    End Function
    Public Function ConvertTo16Bit(ByVal Source As Bitmap) As Bitmap
        If Source.PixelFormat <> PixelFormat.Format16bppRgb555 Then
            Dim temp As Bitmap = AForge.Imaging.Image.Clone(Source, PixelFormat.Format16bppRgb555)
            Return temp
        Else
            Return Source
        End If
    End Function
    Public Function ConvertTo24Bit(ByVal Source As Bitmap) As Bitmap
        If Source.PixelFormat <> PixelFormat.Format24bppRgb Then
            Dim temp As Bitmap = AForge.Imaging.Image.Clone(Source, PixelFormat.Format24bppRgb)
            Return temp
        Else
            Return Source
        End If
    End Function
    Public Function ConvertTo32BitAlpha(ByVal Source As Bitmap) As Bitmap
        If Source.PixelFormat <> PixelFormat.Format32bppArgb Then
            Dim temp As Bitmap = AForge.Imaging.Image.Clone(Source, PixelFormat.Format32bppArgb)
            Return temp
        Else
            Return Source
        End If
    End Function

End Class
